let app = new Vue({
     el: '#app',
     data:{
        books:[
            {
                id:1,
                name:'《算法导论》',
                data:'2006-9',
                price:85,
                count:1,
            },
            {
                id:2,
                name:'《UNIX编程艺术》',
                data:'2006-2',
                price:59,
                count:1
            },
            {
                id:3,
                name:'《编程珠玑》',
                data:'2006-2',
                price:39,
                count:1
            },
            {
                id:4,
                name:'《代码大全》',
                data:'2008-10',
                price:128,
                count:1
            }
        ]
     },
     computed:{
        sum(){
            // let Price=0;    
            // for(var i=0;i<this.books.length;i++)
            // {
            //     Price+=this.books[i].price*this.books[i].count
            // }
            // return Price.toFixed(2)
            return this.books.reduce((preValue,n)=>preValue+n.price*n.count,0)
        }
     },
     methods: {
        less(index){
                this.books[index].count--
        },
        add(index) {
            this.books[index].count++
        },
        Remove(index){
            this.books.splice(index,1)
        }
     },
 })